{include file="common/header" title='$_G.title' keywords='' description='' /}
<style type="text/css">
.thumb>ul>li {
	position: relative;
}
.thumb>ul>li>img {
}
.thumb>ul>li>input {
	position: absolute;
	height: 100%;
	width: 100%;
	left: 0px;
	top: 0px;
	opacity: 0.0;
}
</style>

<div class="container">
    <form id="add" method="post" enctype="multipart/form-data">
    <div class="form-group">
   	  <label for="title">标题</label>
      <input name="title" type="text" class="form-control" id="title">
	</div>
    
    <div class="thumb form-group">
   	  <label for="title">焦点图</label>
      <div id="picker">选择文件</div>
      <ul class="row picker_list list-unstyled">
      	
      	
        
      	<!--
      	<li class="col-md-2">
          <img class="img-thumbnail" src="/public/cloud/images/image.png" width="100%" />
          <input name="thumb[]" type="file" accept="image/*" /> 
        </li>
        <li class="col-md-2">
          <img class="img-thumbnail" src="/public/cloud/images/image.png" width="100%" />
          <input name="thumb[]" type="file" accept="image/*" />
        </li>
        <li class="col-md-2">
          <img class="img-thumbnail" src="/public/cloud/images/image.png" width="100%" />
          <input name="thumb[]" type="file" accept="image/*" />
        </li>
        <li class="col-md-2">
          <img class="img-thumbnail" src="/public/cloud/images/image.png" width="100%" />
          <input name="thumb[]" type="file" accept="image/*" />
        </li>
        <li class="col-md-2">
          <img class="img-thumbnail" src="/public/cloud/images/image.png" width="100%" />
          <input name="thumb[]" type="file" accept="image/*" />
        </li>
        <li class="col-md-2">
          <img class="img-thumbnail" src="/public/cloud/images/image.png" width="100%" />
          <input name="thumb[]" type="file" accept="image/*" />
        </li>
       -->
      </ul>
	</div>
    
    <div class="mod">
    {include file="post/input" /}
    </div>
    
    <div class="form-group">
   	  <label for="description">摘要</label>
      <textarea id="description" name="description" class="form-control" rows="2"></textarea>
	</div>
    
    
    <div class="form-group">
   	  <label for="content">内容</label>
      {include file="../default/common/editor" name="content" value="" /}
	</div>
    
	
    
    <br />
	<input type="submit" class="btn btn-default" id="submit" value="提交">
	
    </form>
</div>

<link rel="stylesheet" type="text/css" href="/public/cloud/css/webuploader.css">
<script src="/public/cloud/script/webuploader.min.js"></script>

<script>

$(function(){
	//上传焦点图
	/*
	var obj = $(".thumb input");   //设置上传按钮的对象
	obj.change(function(e) {
		var imgobj = $(this).siblings("img");
		var objUrl = getObjectURL(this.files[0]);
		if(!objUrl){	//如果图片不存在
			objUrl = "./public/cloud/images/image.png";
		}
		imgobj.attr("src",objUrl);
    });
	//上传焦点图-end
	*/
	
	//检测提交按钮
	$("#submit").click(function(e) {
		//判断再有是否为空，否则写入摘要
		var description = $("#description").val();
		if(description.length <= 0){
			var str = editor.getContentTxt();
			
		  $("#description").val(editor.getContentTxt());
		}
		//摘要-end
		
		//检测标题是否为空
		var msg = '';
		var title = $("#title").val();
		if(title.length < 2){
			var msg = "标题不能为空";	
		}
		if(msg != ''){
			//e.preventDefault();
			alert(msg);
			return false;
		}	
		$("#add").submit();
	});
	//检测提交按钮
	
	
	
	
	
});



var uploader = WebUploader.create({
	auto: true,
    // swf文件路径
    //swf: BASE_URL + '/js/Uploader.swf',
    // 文件接收服务端。
    server: "{:url('webuploader',['aid' => input('aid')])}",
    // 选择文件的按钮。可选。
    // 内部根据当前运行是创建，可能是input元素，也可能是flash.
    pick: '#picker',
    width: 480,
	height: 480,
	
	prepareNextFile : true,
	fileNumLimit : 6,
	
	// 只允许选择图片文件。
    accept: {
        title: 'Images',
        extensions: 'gif,jpg,jpeg,bmp,png',
        mimeTypes: 'image/*'
    }
    
});

$list = $(".picker_list");

// 当有文件添加进来的时候
uploader.on( 'fileQueued', function( file ) {
    var $li = $(
            /*
            '<div id="' + file.id + '" class="file-item thumbnail">' +
                '<img>' +
                '<div class="info">' + file.name + '</div>' +
            '</div>'
            */
            
            '<li class="col-md-2">'+
      		'<img class="img-thumbnail" width="100%" />'+
    		'</li>'
            
            ),
        $img = $li.find('img');


    // $list为容器jQuery实例
    $list.append( $li );

    // 创建缩略图
    // 如果为非图片文件，可以不用调用此方法。
    // thumbnailWidth x thumbnailHeight 为 100 x 100
    uploader.makeThumb( file, function( error, src ) {
        if ( error ) {
            $img.replaceWith('<span>不能预览</span>');
            return;
        }

        $img.attr( 'src', src );
    }, 200, 200 );
});

	
//建立一個可存取到該file的url
function getObjectURL(file) {
	var url = null ; 
	if (window.createObjectURL!=undefined) { // basic
		url = window.createObjectURL(file) ;
	} else if (window.URL!=undefined) { // mozilla(firefox)
		url = window.URL.createObjectURL(file) ;
	} else if (window.webkitURL!=undefined) { // webkit or chrome
		url = window.webkitURL.createObjectURL(file) ;
	}
	return url ;
}
</script>

{include file="common/footer" /}